package com.sensePlusVR.activity.mine;

import org.xutils.x;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.sensePlusVR.base.BaseActivity;
import com.sensePlusVR.bean.UserDto;
import com.sensePlusVR.main.R;
import com.sensePlusVR.net.NetRequestManager;
import com.sensePlusVR.utils.AppManager;
import com.sensePlusVR.utils.Constant;
import com.sensePlusVR.utils.EditTextUtils;
import com.sensePlusVR.utils.MySharedPreferences;
import com.sensePlusVR.utils.MyToast;
import com.sensePlusVR.utils.StringUtils;

/**
 * 
 * @author: Loren
 * @create: 2016-7-28上午11:21:31
 * @desc: 修改用户名
 *
 */
@SuppressWarnings("unused")
@ContentView(R.layout.activity_setting_modify_username)
public class ModifyUNActivity extends BaseActivity{
	
	private static final String TAG = ModifyUNActivity.class.getSimpleName();
	@ViewInject(R.id.title_bar_title_tv)
	private TextView title_bar_title_tv;
	@ViewInject(R.id.title_bar_right_tv)
	private TextView title_bar_right_tv;
	@ViewInject(R.id.setting_modify_username_et)
	private EditText setting_modify_username_et;
	
	@Override
	public void setMyContentView() {
		x.view().inject(this);
	}
	
	@Override
	public void initView() {
		super.initView();
		title_bar_title_tv.setText(R.string.modify_nickname);
		title_bar_right_tv.setText(R.string.save);
		
		String userName = MySharedPreferences.getString2(ModifyUNActivity.this, MySharedPreferences.NAME_NOT_CLEAR,Constant.LOGIN_SUCCESS_SHOWNAME);
		String nickName = "";
		int lastIndex = userName.indexOf("@");
		if(lastIndex == -1)
			nickName = userName;
		else
			nickName = userName.substring(0, lastIndex);
		setting_modify_username_et.setText(nickName);
		setting_modify_username_et.setSelection(setting_modify_username_et.getText().length());
		
		AppManager.getInstance().addActivity(this);
	}
	
	@Event(value = {R.id.title_bar_left_ib,R.id.title_bar_right_tv})
	private void setViewOnClick(View view){
		switch (view.getId()) {
		case R.id.title_bar_left_ib:
			AppManager.getInstance().finishActivity(this);
			break;
		case R.id.title_bar_right_tv:
			//MyToast.showMessage(ModifyUNActivity.this, R.string.nick_name_save);
			checkResult();
			break;
		}
	}
	
	private void checkResult() {
		String userName = EditTextUtils.getText(setting_modify_username_et);
		if (StringUtils.isEmpty(userName)) {
			EditTextUtils.setFocusable(setting_modify_username_et);
			MyToast.showMessage(getApplicationContext(),
					R.string.msg_common_e_null_username);
			return;
		}else{
			UserDto userDtoIn = new UserDto();
			userDtoIn.setShowName(setting_modify_username_et.getText().toString());
			NetRequestManager.startGetNewAccountInfo(ModifyUNActivity.this, userDtoIn);
		}
	}
}








